
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>栈跟队列的区别 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>栈跟队列的区别 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">栈（Stack）和队列（Queue）在数据存取顺序上的根本区别是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">栈是一种后进先出（Last-In-First-Out, LIFO）的数据结构，最后压入的元素将会最先被弹出。而队列是一种先进先出（First-In-First-Out, FIFO）的数据结构，最先进入队列的元素将会最先被访问和移除。</div>
          </div>
          <div class="card-source">来源: 定义和特点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">使用数组实现栈（Stack）的优缺点分别是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">优点是访问速度快（时间复杂度为O(1)）且结构简单。缺点是数组大小固定，可能会导致栈溢出（stack overflow）问题，无法动态调整大小。</div>
          </div>
          <div class="card-source">来源: 栈的内部实现 - 1. 基于数组的实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">使用链表实现队列（Queue）的优缺点分别是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">优点是队列大小动态，可灵活调整，不会出现队列溢出问题。缺点是在空间上有额外的指针开销，访问速度可能略慢于数组实现。</div>
          </div>
          <div class="card-source">来源: 队列的内部实现 - 2. 基于链表的实现</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">栈和队列在插入、删除和访问元素这些基本操作上的时间复杂度是多少？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">栈和队列在插入、删除和访问操作上的时间复杂度都是 O(1)，都具有较高的操作效率。</div>
          </div>
          <div class="card-source">来源: 操作效率 - 结论</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">请列举至少两个栈（Stack）的典型应用场景。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">栈的典型应用场景包括：1. 递归函数的实现；2. 表达式求值（例如逆波兰表达式）；3. 函数调用；4. 回溯算法。</div>
          </div>
          <div class="card-source">来源: 应用场景 - 栈的应用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">请列举至少两个队列（Queue）的典型应用场景。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">队列的典型应用场景包括：1. 任务调度；2. 消息传递（消息队列）；3. 缓冲区管理；4. 广度优先搜索（BFS）；5. 线程池。</div>
          </div>
          <div class="card-source">来源: 应用场景 - 队列的应用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Java中，为什么官方不推荐使用`Stack`类？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为`Stack`类是继承自`Vector`类的遗留类，性能较差。推荐使用更灵活、高效的`Queue`接口及其实现类，如`ArrayDeque`或`LinkedList`来模拟栈。</div>
          </div>
          <div class="card-source">来源: Java中的实现 - 比较</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">栈（Stack）包含哪三种基本操作？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">栈的三种基本操作是：1. 入栈（Push），将元素压入栈顶；2. 出栈（Pop），从栈顶移除元素；3. 获取栈顶元素（Peek），查看栈顶元素但不移除。</div>
          </div>
          <div class="card-source">来源: 定义和特点 - 栈（Stack）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Java中`Queue`接口有哪些常见的实现类，它们各自有什么特点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">常见的实现类有：1. `LinkedList`：实现了`Deque`接口，可作为双端队列或栈使用；2. `ArrayDeque`：底层基于循环数组，提供了高效的队列操作；3. `PriorityQueue`：是一个优先级队列，元素会按照优先级顺序排序。</div>
          </div>
          <div class="card-source">来源: Java中的实现 - 3. Queue 接口的常见实现类</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
